// pages/roomsList/roomsList.js
var common = require('../../utils/common.js');
const app = getApp();
var that = this ;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
    dataList: [],
    feeItemPath:'billFeeItem',
    year: '',
    month:'',
    key:'',
    isyj:'',
    isreduce:'',
  },

  
  getfeeData: function (year,month,key,isyj,isreduce) {
    console.log(year + month + key + 'isreduce' + isreduce)
    common._get('/wx/landlord/charge/item/list', { year: year, month: month, itemKey: key, isforegift: isyj, isreduce: isreduce},
      //成功
      function (res) {
        
        var path = "";
        console.log(res.data);
        if (res.data.success) {
          if (res.data.data.length>0){
            //添加点击展开
            for (var i in res.data.data) {
              res.data.data[i].check = false;
            }
            //判断是否是抄表 6是电费 12是水费
            if (that.data.key == 6 || that.data.key==12) {
              path = "billWEFeeItem";
            } else {
              path = "billFeeItem";
            }
            that.setData({
              dataList: res.data.data,
              feeItemPath: path
            })
          }
          wx.stopPullDownRefresh();
        }
      });
      
  },
  //点击右边的展开图标
  clickRIcon: function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(index)
    this.data.dataList[index].check = !this.data.dataList[index].check;
    this.setData({
      dataList: this.data.dataList
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    this.getfeeData(options.year, options.month, options.key, options.isyj, options.isreduce);
    that.setData({
      year: options.year,
      month: options.month,
      key: options.key,
      isyj: options.isyj,
      isreduce: options.isreduce
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getfeeData(that.data.year, that.data.month, that.data.key, that.data.isyj, that.data.isreduce);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})